<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/21
 * Time: 23:15
 */
namespace app\admin\model\copy;
use think\Db;
use think\Exception;

class CopyFile{
    /**复制文件
     * @param string复制文件夹 $from
     * @param string到的文件夹 $to
     * @param string文件名 $value
     * @param bool $cover
     * @return bool
     */
    public static function mycopy($from='',$to='',$value='',$cover=true){
        $from = rtrim($from,'/');
        $to = rtrim($to,'/');
        if(!$cover){
            if(is_file($to.'/'.$value)){
                return true;
            }
        }
        Db::name('user')->where('id',1)->cursor();
        try{
            copy($from.'/'.$value,$to.'/'.$value);
        }catch (Exception $e){
            chmod($to,0777);
            copy($from.'/'.$value,$to.'/'.$value);
        }
        return true;
    }
}